package com.ruoyi.project.module.pool.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.pool.domain.Pool;
import com.ruoyi.project.module.pool.service.IPoolService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 汇总 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-25
 */
@Controller
@RequestMapping("/module/pool")
public class PoolController extends BaseController
{
    private String prefix = "module/pool";
	
	@Autowired
	private IPoolService poolService;
	
	@RequiresPermissions("module:pool:view")
	@GetMapping()
	public String pool()
	{
	    return prefix + "/pool";
	}
	
	/**
	 * 查询汇总列表
	 */
	@RequiresPermissions("module:pool:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Pool pool)
	{
		startPage();
        List<Pool> list = poolService.selectPoolList(pool);
		return getDataTable(list);
	}
	
	/**
	 * 新增汇总
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存汇总
	 */
	@RequiresPermissions("module:pool:add")
	@Log(title = "汇总", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Pool pool)
	{		
		return toAjax(poolService.insertPool(pool));
	}

	/**
	 * 修改汇总
	 */
	@GetMapping("/edit/{poolId}")
	public String edit(@PathVariable("poolId") Integer poolId, ModelMap mmap)
	{
		Pool pool = poolService.selectPoolById(poolId);
		mmap.put("pool", pool);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存汇总
	 */
	@RequiresPermissions("module:pool:edit")
	@Log(title = "汇总", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Pool pool)
	{		
		return toAjax(poolService.updatePool(pool));
	}
	
	/**
	 * 删除汇总
	 */
	@RequiresPermissions("module:pool:remove")
	@Log(title = "汇总", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(poolService.deletePoolByIds(ids));
	}
	
}
